package com.sui.bigdata.flink.sql.core.metric;


import org.apache.flink.metrics.Counter;
import org.apache.flink.metrics.Meter;

/**
 * @author YongChen
 * @date 2019/12/10 17:14
 * @description
 * @email yong_chen@sui.com
 */
public class ComputeDelayMeter implements Meter {

    private  long num;
    private  long total;

    public ComputeDelayMeter(long num, long total) {
        this.num = num;
        this.total = total;
    }

    @Override
    public void markEvent() {
        num+=1;
        total+=1;
    }

    @Override
    public void markEvent(long l) {
        num+=1;
        total+=l;
    }

    @Override
    public double getRate() {
        return Double.valueOf(String.format("%.2f",Double.valueOf(total)/num));
    }

    @Override
    public long getCount() {
        return total;
    }
}
